<?php
//设置编码
header('Content-type:text/html;charset=utf-8');

//开启session
session_start();

//包含网站配置
include '../../public/wzpeizhi.php';

//包含数据库配置
include '../../public/peizhi.php';

//包含函数库
include '../../public/func.php';

//调用函数连接数据库
$link = db();

//设置时区
date_default_timezone_set('PRC');

//接值板块ID
$bk_id = $_GET['bk_id'];

//查询板块
$bksql = "select bk_name,bk_id from bankuai where bk_id={$bk_id}";

//执行SQL语句
$bkres = mysqli_query($link,$bksql);
			
//获取板块结果
if($bkres && mysqli_num_rows($bkres)){
	$bkarr = mysqli_fetch_assoc($bkres);

?>
<!DOCTYPE html>
<html>

	<!-- 头部包含外部样式 -->
	<head>
		<meta charset="utf-8">
		<title><?php echo WZ_NAME;?></title>
		<meta name="keywords" content="<?php echo WZ_KEY;?>">
		<meta name="description" content="最大的社区网站">
		<link href="../css/liebiao.css" rel="stylesheet">
	</head>
	<!-- 头部结束 ------------------->
	
	<body>
	
		<!-- 主体顶部 -->
		<div id="x">
			<a href="">设为首页</a>
			<a href="">收藏本站</a>
		</div>
		<!-- 顶部结束 ------------->
		
		<div id="y">
		
			<!-- 主体第一部分大盒子a,包含a1,a2,a3三个盒子 -->
			<div id="a">
<?php
		//判断用户是否登录
		if(isset($_SESSION['uname'])){
?>			
			<!-- 用户登录后的执行区间 ------------>
				
				<!-- a1包含 ab和cd两个盒子-->
				<div id="a1">
				
					<div id="ab">
					<div id="aa">
						<img src="../../uploads/<?php echo WZ_LOGO;?>">
					</div>
					<div id="aaa">
			<?php
				$link = db();
				//查询用户信息
				$usersql = "select * from user where name='{$_SESSION['uname']}'";
				$userres = mysqli_query($link,$usersql);
				if($userres && mysqli_num_rows($userres)){
					$userarr = mysqli_fetch_assoc($userres);
				}

		?>			
						<b>欢迎回来: <a href="./geren.php"><?php echo $_SESSION['qx'] == 2 ? '管理员' : '会员' ;?> <?php echo $_SESSION['uname'];?></a>
						<img src="../../uploads/<?php echo $userarr['pic'];?>">
						<?php echo $_SESSION['qx'] == 2 ? '<a href="../../admin.php">管理中心</a>' : '' ;?></b>
					</div>
					</div>
					
					<div id="cd">
						<h3><a href="../dozhuxiao.php">用户注销</a></h3>
					</div>
					
				</div>
				<!-- a1盒子结束 --------------------------->
<?php
			//释放结果
			mysqli_free_result($userres);
			
			}else{
?>				
			<!-- 用户未登录的执行区间 ----------------->
				
				<!-- a1包含 ab和cd两个盒子-->
				<div id="a1">
				
					<div id="ab">
					<div id="aa">
						<img src="../../uploads/<?php echo WZ_LOGO;?>?>">
					</div>
					<div id="aaa">
						<h3><a href="./denglu.php">登录</a></h3>
					</div>
					</div>
					
					<div id="cd">
						<!--<a href="">找回密码</a><br><br>-->
						<h3><a href="./zhuce.php">立即注册</a></h3>
					</div>
					
				</div>
				<!-- a1盒子结束 ------------------------->
<?php
			}
?>
				<!-- a2盒子 -->
				<div id="a2">
					<div id="one"><a href="">论坛</a></div>
					<div id="two"></div>
					<div id="three">	
						<select name="daohang">
							<option value="1">快捷导航</option>
							<option></option>
						</select>
		
					</div>
				</div>
				<!-- a2盒子结束 ------------------->
				
				<!-- a3盒子 -->
				<div id="a3">
					<input type="text" name="sousuo" value="请输入搜索内容">
					<select name="tiezi">
						<option>帖子</option>
						<option>用户</option>
					</select>
					<img src="../tupian/sousuo.gif">
					热搜:<a href="">活动</a>
						<a href="">交友</a>
						<a href="">discuz</a>
				</div>
				<!-- a3盒子结束 ---------------->
				
			</div>
			<!-- 主体第一部分a结束 ------------------>
			
			<!-- 第二部分大盒子b,包含 b1,b2两个盒子 -->
			<div id="b">
			
				<b><div id="b1">
					<img src="../tupian/887643d2.bmp.bmp">
					&gt;<a href="">论坛</a>
					&gt;<a href="">DISCUZ!</a>
					&gt;<a href=""><?php echo $bkarr['bk_name'];?>版块</a>
				</div></b>
				
				<div id="b2">
					<div id="b21">
					</div>
					<div id="b22">
						<img src="../tupian/shoucang.gif"><a href="">收藏本版</a>|
						<img src="../tupian/dingyue.gif"><a href="">订阅</a>|
						<img src="../tupian/huishou.gif"><a href="">回收站</a>|
						<a href="">管理面板</a>
					</div>
				</div>
				
			</div>
			<!-- 第二部分b盒子结束 ------------------>
			
			<!-- 第三部分大盒子c,包含 c1,c2,c3,c4四个盒子 -->
			<div id="c">
			
				<div id="c1">
					<div id="c11">
						<!--<img src="../tupian/pn_post.png">-->
						<h3><a href="./fatie.php?bk_id=<?php echo $bk_id;?>">发帖</a></h3>
					</div>
					<div id="c12">
						<h3><a href="./shouye.php">返回首页</a></h3>
					</div>
				</div>
				
				<div id="c2">
					<b><div id="c21">
						<div id="CX">
							<div id="C1">
								全部主贴
							</div>
							<div id="C2">

							</div>
						</div>
						<div id="CY">
							发表时间
						</div>
					</div></b>
						
					<div>
						<form action="./liebiao.php" method="get">
							<input type="hidden" name="bk_id" value="<?php echo $bk_id;?>">
								<b>主贴名称:&nbsp;<input type="text" name="title"></b>
								<input type="submit" value="查询">
						</form>
	
						<div>
							<h3><div><?php echo $bkarr['bk_name'];?>板块</div></h3>
							
						</div>
					
		
<?php			
				//搜索
				if(!empty($_GET['title'])){
					$title = $_GET['title'];
					$where = "and title like '%{$title}%'";
					$duo = "&title={$title}";
				}else{
					$where = '';
					$duo = '';
					}
					
				  //分页
				  //当前页
				  $current = isset($_GET['page']) ? $_GET['page'] : 1 ;
			
				  //每页条数
				  $row = 2;
				  
				  //第几页
				  $page = ($current - 1) * $row;

				  $limit = "limit {$page},{$row}";
				  
				  //计算帖子总数
				  $sumsql = "select count(*) from fatie where bk_id={$bk_id} and huishou=1";

				  //执行SQL语句
				  $sumres = mysqli_query($link,$sumsql);

				  //获取结果 总数
				  if($sumres && mysqli_num_rows($sumres)){
					$sum = mysqli_fetch_row($sumres);
					mysqli_free_result($sumres);
					$rows = $sum[0];
				  }

				  //计算总页数
				  if($rows == 0){
						$sumpage = 1;
					}else{
						$sumpage = ceil($rows / $row);
					}
					
				  //判断上一页
				  $prev = $current - 1 ;
				  if($prev < 1){
					$prev = 1;
				  }
				  
				  //尾页
				  $end = $sumpage;
				  
				  //判断下一页
				  $next = $current + 1 ;
				  if($next >= $sumpage){
					$next = $sumpage;
				  }

				//查询发帖
				$sql = "select * from fatie f where bk_id={$bkarr['bk_id']} and huishou=1 {$where} {$limit}";

				//执行SQL语句
				$res = mysqli_query($link,$sql);
				
				//获取发帖信息
				if($res && mysqli_num_rows($res)){
					while($tiezi = mysqli_fetch_assoc($res)){

?>					
					<div id="c22"><b>
						<div id="CX2">
							<div id="C3">
								<img src="../tupian/3.jpg">
									<a href="./xiangqing.php?bk_id=<?php echo $bk_id;?>&tz_id=<?php echo $tiezi['id'];?>"><?php echo $tiezi['title'];?></a>
								<img src="../tupian/5.jpg">
							</div>
							<div id="C4">
								<a href=""><?php echo $tiezi['u_name'];?></a>&nbsp;&nbsp;
								<a href="">发表于<?php echo date('Y-m-d H:i:s',$tiezi['ft_time']);?></a>
							</div>
						</div>
						<div id="CY2">
							
						</div>
					</b></div>
					
<?php
					}
				}
?>					
					</div>
														
<?php
			}	
			
			//释放结果
			mysqli_free_result($res);
			mysqli_free_result($bkres);
			
			//关闭数据库连接
			mysqli_close($link);
?>					
					
				</div>
			</div><br>
					<b><a href="./liebiao.php?page=1<?php echo $duo;?>&bk_id=<?php echo $bk_id;?>">首页</a>
					<a href="./liebiao.php?page=<?php echo $prev.$duo;?>&bk_id=<?php echo $bk_id;?>">上一页</a>
					<a href="./liebiao.php?page=<?php echo $next.$duo;?>&bk_id=<?php echo $bk_id;?>">下一页</a>
					<a href="./liebiao.php?page=<?php echo $end.$duo;?>&bk_id=<?php echo $bk_id;?>">尾页</a></b><br><br>
			<!-- 第三部分c盒子结束 ------------------>
			
			
<?php
//包含页脚
include '../public/footer.php';
?>
	</body>
</html>